﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using nHydrate.Generator.Common.Util;

namespace nHydrate.Dsl
{
	partial class Composite
	{
		public string CamelName
		{
			get { return StringHelper.DatabaseNameToCamelCase(this.PascalName); }
		}

		public string DatabaseName
		{
			get { return this.Name; }
		}

		public string PascalName
		{
			get
			{
				if (!string.IsNullOrEmpty(this.CodeFacade))
					return StringHelper.DatabaseNameToPascalCase(this.CodeFacade);
				else
					return StringHelper.DatabaseNameToPascalCase(this.Name);
			}
		}

		/// <summary>
		/// Returns the generated fields for this composite
		/// </summary>
		public IEnumerable<Field> GeneratedColumns
		{
			get { return this.GetFields().Where(x => x.IsGenerated).OrderBy(x => x.Name); }
		}

		/// <summary>
		/// Returns all fields for this composite
		/// </summary>
		/// <returns></returns>
		public IEnumerable<Field> GetFields()
		{
			var retval = new List<Field>();
			foreach (var compositeField in this.Fields)
			{
				var field = this.Entity.Fields.FirstOrDefault(x => x.Id == compositeField.FieldId);
				if (field != null)
				{
					retval.Add(field);
				}
			}
			return retval.OrderBy(x => x.Name);
		}

		public override string ToString()
		{
			return this.Name;
		}

	}

	partial class CompositeBase
	{
		private bool CanMergeCompositeField(Microsoft.VisualStudio.Modeling.ProtoElementBase rootElement, Microsoft.VisualStudio.Modeling.ElementGroupPrototype elementGroupPrototype)
		{
			return false;
		}
	}

}
